package com.springdemo.annotation;

import java.util.Scanner;

public class MainTest {


        //   6,3,5,4,6
        //  2,2,6,5,4
        //  10
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] valueArray = scanner.nextLine().split(",");
        String[] weightArray = scanner.nextLine().split(",");
        String capacity=scanner.nextLine();
        Baby[] babys = new Baby[valueArray.length];
        for (int i = 0; i < valueArray.length; i++) {
          Baby baby= new Baby();
          baby.setValue(Integer.parseInt(valueArray[i]));
            baby.setWeight(Integer.parseInt(weightArray[i]));
            baby.setOdds(Float.parseFloat(valueArray[i])/Float.parseFloat(weightArray[i]));
            babys[i]=baby;
        }
        Baby[] babies = sortFloat( babys);
        Integer nowWeight=0;
        Integer nowValue=0;
        for (Baby aFloat : babies) {
          //将宝贝重量相加
            nowWeight+=aFloat.getWeight();
            if (nowWeight<Integer.parseInt(capacity)){
                nowValue+=aFloat.getValue();
            }
        }

        System.out.println(nowValue);
    }
    //使用冒泡排序按照降序将价值比物品排列
    private static Baby[] sortFloat(Baby[] floats) {
        for (int i = 0; i < floats.length-1; i++) {
            for (int j = 0; j <floats.length-i-1 ; j++) {
                if (floats[j].getOdds()<floats[j+1].getOdds()){
                    Baby temp=floats[j];
                    floats[j]=floats[j+1];
                    floats[j+1]=temp;
                }
            }
        }
        return floats;
    }


}

class Baby{
    private Integer value;
    private Integer weight;
    private  Float odds;

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public Float getOdds() {
        return odds;
    }

    public void setOdds(Float odds) {
        this.odds = odds;
    }
}